package com.tc.quartz.frame.base;


import com.tc.quartz.frame.bean.RespBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * spring mvc controller基类
 *
 * @author yongjin.ye
 *
 * quartz 控制台
 */
public abstract class BaseController {

	protected Logger log = LoggerFactory.getLogger(this.getClass());

	protected static final String ERROR         = "error";
	protected static final String SUCCESS       = "success";
	protected static final String ERROR_MSG_KEY = "errorMsg";

	/**
	 * 获取HttpServletRequest对象
	 */
	protected HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public String finalException(Exception ex) {
		RespBean bean = new RespBean();
		bean.setCode("ERROR");
		bean.setMessage("系统异常," + ex.getMessage());
		return bean.toJson();
	}

}
